<template>
	<view class="mine-container" :style="{height: `${windowHeight}px`}">
		<!--顶部个人信息栏-->
		<view class="header-section">
			<view class="flex padding justify-between" :style="{'margin-top':menuHeight+'px'}">
				<view class="flex align-center">
					<!-- <view v-if="!avatar" class="cu-avatar xl radius bg-white">
						<view class="iconfont icon-people text-gray icon"></view>
					</view> -->
					<image @click="handleToAvatar" :src="avatar || '/static/images/avatar.png'" class="cu-avatar xl bg-gray radius"
						mode="widthFix">
					</image>
					<view v-if="!name" @click="handleToLogin" class="login-tip">
						点击登录
					</view>
					<view v-if="name" @click="handleToInfo" class="user-info">
						<view class="text-xxl text-bold">
							{{ name }}
						</view>
						<view class="">
							<text>{{phonenumber}}</text>
						</view>
					</view>
				</view>
				<view @click="handleToInfo" class="flex align-end">
					<text>更多</text>
					<view class="iconfont icon-right"></view>
				</view>
			</view>
			<view class="padding-lr flex">
				<text>当前基地：</text>
				<view class="flex align-center" @click="handleToPage('base')">
					<text class="padding-right-xs">{{currentBase}}</text>
					<van-icon name="exchange" />
				</view>
			</view>
		</view>

		<view class="content-section">
			<view class="mine-actions grid col-3 text-center">
				<view class="action-item" @click="handleToPage('base')">
					<!-- <view class="iconfont icon-dianzan text-green icon"></view> -->
					<image src="/static/images/mine/base.png" mode=""></image>
					<text class="text">生产基地</text>
				</view>
				<view class="action-item" @click="handleToPage('pond')">
					<image src="/static/images/mine/pond.png" mode=""></image>
					<text class="text">养殖塘口</text>
				</view>
				<view class="action-item" @click="handleToPage('equipment')">
					<image src="/static/images/mine/device.png" mode=""></image>
					<text class="text">所有设备</text>
				</view>
				<!--  <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-community text-mauve icon"></view>
          <text class="text">反馈社区</text>
        </view> -->

			</view>

			<view class="cu-card case padding-lr radius">
				<view class="bg-white padding-lr padding-tb-sm border-bottom">
					<text class="text-lg text-bold">基地数据</text>
				</view>
				<view class="grid col-3 no-border bg-white padding-tb-sm padding-lr">
					<view class="padding-bottom">
						<text class="text-gray">养殖塘口</text>
						<view class="text-xl">
							<text class="text-bold">{{baseStatistics.culturePondCnt || '-'}}</text>
							<text class="text-df padding-left-xs">个</text>
						</view>
					</view>
					<view class="">
						<text class="text-gray">养殖面积</text>
						<view class="text-xl">
							<text class="text-bold">{{baseStatistics.cultureAreaSum || '-'}}</text>
							<text class="text-df padding-left-xs">亩</text>
						</view>
					</view>
					<view class="">
						<text class="text-gray">养殖种类</text>
						<view class="text-xl">
							<text class="text-bold">{{baseStatistics.offspringSeedCnt || '-'}}</text>
							<text class="text-df padding-left-xs">种</text>
						</view>
					</view>
					<view class="">
						<text class="text-gray">养殖数量</text>
						<view class="text-xl">
							<text class="text-bold">{{baseStatistics.breedQuantity || '-'}}</text>
							<text class="text-df padding-left-xs">尾</text>
						</view>
					</view>
					<view class="">
						<text class="text-gray">支出费用</text>
						<view class="text-xl">
							<text class="text-bold">{{baseStatistics.expenses || '-'}}</text>
							<text class="text-df padding-left-xs">元</text>
						</view>
					</view>
					<view class="">
						<text class="text-gray">收入总额</text>
						<view class="text-xl">
							<text class="text-bold">{{baseStatistics.income || '-'}}</text>
							<text class="text-df padding-left-xs">元</text>
						</view>
					</view>
				</view>
			</view>

			<view class="menu-list">
				<view class="list-cell list-cell-arrow" @click="handleToEditInfo">
					<view class="menu-item-box">
						<view class="iconfont icon-user menu-icon"></view>
						<view>编辑资料</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="handleAbout">
					<view class="menu-item-box">
						<view class="iconfont icon-aixin menu-icon"></view>
						<view>关于我们</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="handleToSetting">
					<view class="menu-item-box">
						<view class="iconfont icon-setting menu-icon"></view>
						<view>应用设置</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage'
	import {
		statisticsBase
	} from '@/api/mine/statistics'
	export default {
		data() {
			return {
				name: this.$store.state.user.name,
				phonenumber: this.$store.state.user.phonenumber,
				version: getApp().globalData.config.appInfo.version,
				menuHeight: getApp().globalData.menuHeight,
				baseStatistics: {},
				queryParams: {
					productionBaseId: undefined
				}
			}
		},
		computed: {
			currentBase() {
				return this.$store.state.user.baseInfo.name
			},
			avatar() {
				return this.$store.state.user.avatar
			},
			windowHeight() {
				return uni.getSystemInfoSync().windowHeight - 50
			}
		},
		onShow() {
			this.queryParams.productionBaseId = this.$store.state.user.baseInfo.id
			this.getBaseStatistics()
		},
		methods: {
			getBaseStatistics() {

				statisticsBase(this.queryParams).then(res => {
					this.baseStatistics = res.data
				})
			},
			handleToPage(path) {
				switch (path) {
					case 'base':
						this.$tab.navigateTo('/pages/mine/base/change')
						break;
					case 'pond':
						this.$tab.navigateTo('/pages/mine/pond/index')
						break;
					case 'equipment':
						this.$tab.navigateTo('/pages/mine/equipment/index')
						break;
				}
			},
			handleToInfo() {
				this.$tab.navigateTo('/pages/mine/info/index')
			},
			handleToEditInfo() {
				this.$tab.navigateTo('/pages/mine/info/edit')
			},
			handleToSetting() {
				this.$tab.navigateTo('/pages/mine/setting/index')
			},
			handleToLogin() {
				this.$tab.reLaunch('/pages/login')
			},
			handleToAvatar() {
				this.$tab.navigateTo('/pages/mine/avatar/index')
			},
			handleLogout() {
				this.$modal.confirm('确定注销并退出系统吗？').then(() => {
					this.$store.dispatch('LogOut').then(() => {
						this.$tab.reLaunch('/pages/index')
					})
				})
			},
			handleHelp() {
				this.$tab.navigateTo('/pages/mine/help/index')
			},
			handleAbout() {
				this.$tab.navigateTo('/pages/mine/about/index')
			},
			handleJiaoLiuQun() {
				this.$modal.showToast('QQ群：①133713780、②146013835')
			},
			handleBuilding() {
				this.$modal.showToast('模块建设中~')
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f5f6f7;
	}

	.mine-container {
		width: 100%;
		height: 100%;


		.header-section {
			padding: 15px 15px 45px 15px;
			background-color: #3c96f3;
			color: white;

			.login-tip {
				font-size: 18px;
				margin-left: 10px;
			}

			.cu-avatar {
				border: 2px solid #eaeaea;

				.icon {
					font-size: 40px;
				}
			}

			.user-info {
				margin-left: 15px;

				.u_title {
					font-size: 18px;
					line-height: 30px;
				}
			}
		}

		.content-section {
			position: relative;
			top: -50px;

			.mine-actions {
				margin: 15px 15px;
				padding: 20px 0px;
				border-radius: 8px;
				background-color: white;

				.action-item {
					.icon {
						font-size: 28px;
					}
					image{
						width: 28px;
						height: 28px;
					}

					.text {
						display: block;
						font-size: 13px;
						margin: 8px 0px;
					}
				}
			}
		}
	}
</style>